﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script src="~/js/jquery-1.8.3.min.js"></script>

    <script src="@Url.Content("~/js/ajaxfileuploadv2.1.js")"></script>
    <script src="@Url.Content("~/js/TMajaxuploadimg.js")"></script>

    <link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/uploadimgcss.css")" />
    <title>add</title>

</head>
<body style="padding-left:20%">
    <form onsubmit="return CheckForm()" id="form1">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">选择图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <!--图片上传 start -->
                <div class="upload_imgs">
                    <div class="imglist">
                        <div class="uploader_input_wrp">
                            <!--上传-->
                            <input class="uploader_input" id="uploader_input" name="uploader_input" onchange="ajaxImgFileUpload(this)" type="file" accept="image/jpg,image/jpeg,image/png,image/gif" multiple="" />
                            <input type="hidden" name="Images" id="Images" value="" />
                        </div>
                    </div>
                </div>
                <!--图片上传 end -->
            </div>
        </div>

        <br />
        <br />
        <br />
        <br />
        <br />

        <input name="Name" id="Name" placeholder="请输入你的名字" style="height:30px;width:100px" />

        <br />
        <br />
        <input type="submit" id="submit" value="提交" style="width:100px" />

    </form>
    <script>
        var totalimgCount = 1;//允许上传的总个数
        function getimglist() {
            var imglist = $("#uploader_input").parent().parent().find("img");
            var imgstr = "";
            $.each(imglist, function () {
                imgstr += $(this).attr("src") + ",";
            })
            if (imgstr.length > 0) {
                imgstr = imgstr.substring(0, imgstr.length - 1);
            }
            //alert(imgstr);
            $("#Images").val(imgstr);
        }

        function CheckForm() {
            getimglist();

            if ($("#Images").val() == "") {
                alert("请选择图片");
                return false;
            }
            if ($("#Name").val() == "") {
                alert("请输入姓名");
                return false;
            }
            $.post("@Url.Action("AddSave", "Home")", $("#form1").serialize(), function (msg) {
                if (msg.result) {
                    alert("ok，已保存");
                }
                else {
                    alert("error， 没有识别出来");
                }
            });
            return false;
        }

    </script>
</body>
</html>
